# -*- coding: utf-8 -*-

# from enum import Enum
# from odoo.tools.misc import unique
from odoo import models, fields, api

# @unique
class SType():
    student = 'student.student'
    course = 'student.course'
    score = 'student.score'

class student(models.Model):
    _name = SType.student
    _description = SType.student

    name = fields.Char()
    # value = fields.Integer()
    # value2 = fields.Float(compute="_value_pc", store=True)
    # description = fields.Text()
    studentID = fields.Char()   # 学号
    
    # @api.depends('value')
    # def _value_pc(self):
        # for record in self:
            # record.value2 = float(record.value) / 100
            
    course_id = fields.Many2many(SType.course, relation='student_score',
     column1='student_id', column2='course_id', string='选取课程')

class course( models.Model ):
    _name = SType.course
    _description = SType.course
    name = fields.Char()
    description = fields.Text()
    
    '''
    Many2many field; the value of such a field is the recordset.

comodel_name – name of the target model (string) mandatory except in the case of related or extended fields
relation (str) – optional name of the table that stores the relation in the database
column1 (str) – optional name of the column referring to “these” records in the table relation
column2 (str) – optional name of the column referring to “those” records in the table relation
    '''
    student_ids = fields.Many2many( SType.student, relation='student_score', 
    column1='course_id', column2='student_id', string='学生ids')
    
    
class score(models.Model):
    _name = SType.score
    _description = SType.score
    score = fields.Float('score', required=True)
    description = fields.Text()
    

    student_id = fields.Many2one(SType.student, '学生')
    course_id = fields.Many2one( SType.course, '课程' )
    